<runtimeJavaCodeRecursesNodes>

Node and network are the same type of thing: Object array of the same size, containing Object and double arrays with sizes depending on eachother.

A heapQueue is 2 arrays: Object and flo. The details of what a heapQueue is is in file heapQueue*.xml.

A Flofunc has these functions:
	public void run(double flo[], int i);
	public int frsiz();

A Flofunc can be created by Javassist, Beanshell, or other dynamic Java compilers. It is created for each evolved variation of nodeFunc.

A nodeFunc takes 1 parameter: a node or network (which are the same type of thing) to execute. If each node/network has 1 heapQueue, then execution could recurse into nodes, but would not recurse if all heapQueues except the root are empty, which is the original design for Audivolv I was considering. Audivolv will be backward compatible with that.

<question>
	Can a node have more than 1 heapQueue?
	<possibleAnswer>
		I prefer that it can have any small constant quantity of heapqueues.
		This complicates recursive control-flow, but is worth it.
	</possibleAnswer>
</question>

<question>
	Can a heapQueue have more than 2 arrays? The 2 required arrays are Object and flo.
</question>

<question>
	Should recursive control-flow be controlled by 1 heapQueue used as a stack? It would be a little slower, but infinite recursion would be prevented because a network would recurse 1 time when you execute the network. The current design would recurse until some node executes.
</question>

<question>
	Can there be more types of control-flow or sorting than heapQueue and linear iteration? For example, similar to heapQueue except the whole list is sorted instead of just the first index guaranteed to have the highest sort value.
</question>

<question>
	Which nodes should each heapQueue contain? Which should be added and removed, and when?
</question>

<question>
	Should a heapQueue (or other sortable data structure) work in both direction?
	That means I can ask about a specific node and get its position in the heapQueue
	or ask about position and get the node.
	<possibleAlgorithm>
		Example neural node:
			int heapQueue[]
			int heapQueueReverseIndex[] //forgot this one. TODO update the text below because I added this.
			double heapQueueSortNumbers[]
			Object neuralNodeChilds[]
			double neuralNodeChildWeights[]
		In that neural node, only int heapQueue[] is reordered. The other arrays are aligned to eachother.
		This algorithm requires the nodes in the heapQueue also be childs of the node, but there can be other child arrays in the same node that do not have a heapQueue.
		Its not that much slower but is more complex. It requires the heapQueue have at least 3 arrays instead of at least 2.
		It has a smaller Big-O if there are many arrays in the heapQueue. Only 1 array is reordered.
		<question>
			Should the int array be a double array which only has integers?
			It could still be used with Flofuncs, which only take doubles, by casting.
			It must be cast either way, so that is not slower, but it does take less memory.
			It more complex because its a third type of array (Object, double, int).
		</question>
		<question>
			Should index 0 in the int array be the size of the array, allowing the array to be resized efficiently?
			That would only be effective if all 3 arrays for the heapQueue were resized the same efficient way,
			which means the number of nodes in the Object array never equals that array's size.
		</question>
		I forgot something. For reverse lookup, 4 arrays are needed, not just 3.
		The forth is int heapQueueReverseIndex[] and is aligned with all arrays except the other int array.
		If you know the index of a node in Object neuralNodeChilds[], you can get the index in int heapQueue[].
		<cost>
			Each time a node moves in the heapQueue, which is caused by 1 double value changing, 2 values in each of 3 arrays must be traded.
		</cost>
	</possibleAlgorithm>
</question>

<question>
	Can an int array efficiently be used to keep all nodes in an Object array sorted at all times, by using ints in the array as pointers into that array to define a binary tree?
</question>

There are 3 main data structures I am considering. Maybe all should be available for evolved things to choose from:
(1) Linear array thats always full.
(2) A heapQueue is at least 4 arrays: int heapQueue[], int heapQueueReverseIndex[], double heapQueueSortNumbers[], Object heapQueueNodes[].
	heapQueue[0] is always the used size of the heapQueue array. Usable range always starts at index 1.
	The other 3 arrays must all be the same size, but this can be done in multiple ways. They could be the same size as int heapQueue[]
	or they could be aligned to some "linear array" as described above. I have not decide that yet.
(3) A sortedList is similar to a heapQueue but the whole list is sorted instead of just the first index.
	I have not decided what data structures to use for sortedList. Self balancing trees have Big-O of log time, but are still too slow for changing the sort value of nodes. All other trees are too slow for insert node and delete node. All of these are complex. This must take very little memory because it will sometimes be used in each node of a network to sort its child nodes.
	//TODO Where to store list of empty indexs?
	//When delete an index, it becomes empty. When a node splits, 2 empty index are used.

<possibleDetailsOfSortedList>
	int sortedListLeft[] //size x
	int sortedListRight[] //same size as sortedListLeft
	int sortedListReverseIndex[]
	double sortedListValue[] //same size as sortedListReverseIndex
	Object sortedListNode[] //same size as sortedListReverseIndex
</possibleDetailsOfSortedList>

<possibleDetailsOfSortedList>
	int sortedListLeftRight[] //even index are left child pointers, odd index right.
	int sortedListReverseIndex[] //pointer into sortedListLeftRight. Can be even or odd.
	//To save memory, index x is a node pointer (points into sortedListNode)
	//if sortedListReverseIndex[sortedListLeftRight[x]] == x,
	//else x is a tree pointer (points into sortedListLeftRight).
	double sortedListValue[]
	Object sortedListNode[]
</possibleDetailsOfSortedList>

<possibleDetailsOfSortedList>
	int sortedListLeft[] //pointer into these 3 tree arrays
	int sortedListData[] //pointer into sortedListNode
	int sortedListRight[] //pointer into these 3 tree arrays
	//TODO sortedListReverseIndex
	double sortedListValue[]
	Object sortedListNode[]
</possibleDetailsOfSortedList>

<possibleDetailsOfSortedList>
	int sortedListQuad[] //Each block of 4 index are a tree node. Each int points into this array or sortedListNode
	//Dont need sortedListReverseIndex because that can be found in log time by using sortedListValue
	double sortedListValue[]
	Object sortedListNode[]
</possibleDetailsOfSortedList>

<possibleDetailsOfSortedList>
	int sortedListShallowTree[][] //contains variable-size int arrays. Ints are index for sortedListNode.
	//First int in each int array is size used in that array.
	//Use binary-search on sortedListShallowTree then linear search on an int array.
	//When an int array gets too big, move ints to its adjacent arrays.
	//Less often than that, rebuild the whole sortedListShallowTree as arrays with size 8
	double sortedListValue[]
	Object sortedListNode[]
	//ERROR: Big-O(total data size) to use index to find node. Int arrays do not know their overall position,
	//and if they stored that, there is a different Big-O problem.
</possibleDetailsOfSortedList>

sortedList is complex. Lets write code for that later, and for now, use only linearArray and heapQueue.


A big problem with heapQueue occurs in the simplest network, where theres only 1 heapQueue which is in the root node. Its a neural network, where all nodes are child of the root node (the network). Each neural node has many child neural nodes, which are all in that 1 heapQueue. When a neural node executes, it changes the flos of its child neural nodes in the heapQueue. To do that, it has to know the index of each child in the heapQueue, but thats a Big-O problem because child nodes are stored as Object instead of int index.

A possible solution is to give each node a unique number and always sort arrays of node by those numbers. All lists could be searched for any node in log time. For a 16000 node network, the log is 14, which is slow, but will work if nothing faster is found. Its appoximately the same speed as a java.util.Map but requires no nonarray Java Objects.

The java.lang.Object.hashCode() function can not be used for sorting node arrays because networks of nodes saved to bytes can not be created from that file after Java is restarted because the hashcodes will be different and the same combinations of sorting in node lists will be exponentially hard to make consistent in a whole network of nodes. Do not use hashcode for sorting.

If each node has a unique flo (Java type double) at index 0 (or in a size 1 array at index 0), then eventually 2 variations of the same node will be combined in the same network, and 1 of them will have to get a new unique flo. What problems will that cause? Where are flos used as pointers?

Object[]{
	double[]{ 3453463546. } //unique flo of this node
	//Should unique flo be a String instead of flo? Should it be some other unique sortable Object?
	double[]{ Double.POSITIVE_INFINITY 111112345. 346345. 2345234. 5235345. } //unique flos of nodes in this heapQueue
	//Instead of the double[] above, it could be Object[] containing the nodes which contain those same unique flos.
	int[]{  } //index in me is index of node below. Value in me is index in the heapQueue above.
	double[]{ .3 .4 9.5 .123 } //flo values the heapQueue is sorted by
	Object[]{ nodeb nodef nodeg nodec } //nodes paired with the flo values in the array above. Each node has one of the unique flos in the heapQueue flo array.
}

Iterating over the heapQueue takes log squared time, which is too slow. If it contained integer indexs instead of unique flo of each node, it would be log time instead of log squared time. But does that work for multiple nodes sharing 1 heapQueue for the network?

If the unique thing (flo, string, or whatever it is) is never used as a pointer then hashcode could be used instead, assuming order of nodes in array of node never matters, which is a goal of the design of audivolv networks.


</runtimeJavaCodeRecursesNodes>